package com.byxm.wlgw.query;

import com.byxm.wlgw.bean.GwcxxBean;



public class GwcxxQuery{
	/**
	 * 将商品型号价格加入购物车
	 */

	public String addSptogwcSql(){
		StringBuffer sql=new StringBuffer();
		sql.append("insert into gwcxx (yhxxid,spxxid,spxhid,spsl)values(?,?,?,?)");
		return sql.toString();
	}
	
	/**
	 * 验证购物车信息内是否有相同商品
	 */
	public String getGwcxxByxtsp(){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from gwcxx where yhxxid=? and spxxid=? and spxhid=?");
		return sql.toString();
	}
	/**
	 * 给相同商品 的加商品数量
	 */
	public String addGwcxxSpsl(){
		StringBuffer sql=new StringBuffer();
		sql.append("update gwcxx set spsl=spsl+? where yhxxid=? and spxxid=? and spxhid=?");
		return sql.toString();
	}
	
	/**
	 * 获得购物车信息
	 * @param yhxxid
	 * @return
	 */
	public String getGwcxxByYhxxid(int yhxxid){
		StringBuffer sql=new StringBuffer();
		sql.append("select t1.*,t2.sptp,t2.spbt,t2.spsj,t3.spxhnr ");
		sql.append(" from ");
		sql.append(" gwcxx t1 left join spxx t2 on t1.spxxid=t2.spxxid ");
		sql.append(" left join spxh t3 on t1.spxhid=t3.xhid ");
		sql.append(" where yhxxid=").append(yhxxid);
		return sql.toString();
	}
	/**
	 * 删除购物车商品
	 */
	public String delteGwcxx(GwcxxBean gwcxx){
		StringBuffer sql=new StringBuffer();
		sql.append("delete from gwcxx where ");
		if(gwcxx.getYhxxid()!=0){
			sql.append("yhxxid=").append(gwcxx.getYhxxid());
		}
		if(gwcxx.getGwcxxid()!=0){
			sql.append(" and ");
			sql.append("gwcxxid=").append(gwcxx.getGwcxxid());
		}
		return sql.toString();
	}
	/**
	 * 更新购物车信息
	 */
	public String updateGwcxxSql(){
		StringBuffer sql=new StringBuffer();
		sql.append("update gwcxx SET spsl=? where gwcxxid=?");
		return sql.toString();
	}
}
